//
//  LGDiseaseOverviewDiseaseCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/10/16.
//

#import "LGDiseaseOverviewDiseaseCell.h"

@interface LGDiseaseOverviewDiseaseCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)NSMutableArray *itemArray;

@end

@implementation LGDiseaseOverviewDiseaseCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataArray:(NSArray *)dataArray{
    _dataArray = dataArray;
    //共病
    for (UILabel *itemLabel in self.itemArray) {
        [itemLabel removeFromSuperview];
    }
    [self.itemArray removeAllObjects];
    CGFloat itemTop = viewPix(12);
    CGFloat itemLeft = viewPix(12);
    for (NSInteger i=0; i<dataArray.count; i++) {
        NSString *content = LGNSString(dataArray[i]);
        CGFloat textWidth = [content textWidthWithFont:LGFont(12) maxHeight:MAXFLOAT]+6;
        itemTop  = ((itemLeft+textWidth+viewPix(8))>=(Screen_W-viewPix(56))) ? itemTop+viewPix(24):itemTop;
        itemLeft = ((itemLeft+textWidth+viewPix(8))>=(Screen_W-viewPix(56))) ? viewPix(12):itemLeft;
       
        UILabel *itemLabel = [UILabel lableWithText:dataArray[i] colorString:@"#4C87FD" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
        itemLabel.frame = CGRectMake(itemLeft, itemTop, textWidth+viewPix(8), viewPix(16));
        itemLabel.layer.borderColor = [UIColor colorWithString:@"#4C87FD"].CGColor;
        itemLabel.layer.borderWidth = 1;
        itemLabel.cornerRidus = viewPix(8);
        [self.baseView addSubview:itemLabel];
        [self.itemArray addObject:itemLabel];
        itemLeft += textWidth+viewPix(16);
    }
    CGFloat itemHeight = (dataArray.count>0) ? itemTop+viewPix(20) : 1;
    [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(itemHeight+viewPix(5)));
    }];
}


#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.height.equalTo(@(1));
    }];
    
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:0];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(NSMutableArray *)itemArray{
    if(!_itemArray){
        _itemArray = [NSMutableArray array];
    }
    return _itemArray;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
